import * as http from 'http';
import * as fs from 'fs';


const hostname = '127.0.0.1';
const port = 3000;

/** 创建服务器，参数为请求处理函数 */
const server = http.createServer((req, res) => {
  res.statusCode = 200;
  /** 中文文件名必须编码 */
  let filename = encodeURI('我的.js');
  res.setHeader('Content-Disposition','attachment;filename=' + filename);
  res.write(fs.readFileSync("./helloworld.js"));
  res.end();
});

/** 服务器开始监听，调用钩子 */
server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});